/**
 * Date:2021年4月26日 下午3:22:40
 * Copyright (c) 2021, www.bwbroad.com All Rights Reserved
 */

package com.xue.antlr.mysql;

import java.util.HashSet;
import java.util.Set;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;

/**
 * Description: TODO <br/>
 * Date:2021年4月26日 下午3:22:40 <br/>
 * 
 * @author xuejianxin
 */
public abstract class MySQLBaseLexer extends Lexer implements IMySQLBase {

	protected boolean inVersionComment = false;

	public MySQLBaseLexer(CharStream input) {
		super(input);
	}

	protected int determineFunction(int nowSymbol) {
		return 0;
	}

	protected void emitDot() {

	}

	protected int determineNumericType(String text) {
		// MySQLLexer::INT_NUMBER;
		// MySQLLexer::LONG_NUMBER;
		// MySQLLexer::DECIMAL_NUMBER;
		// MySQLLexer::ULONGLONG_NUMBER;
		return MySQLLexer.LONG_NUMBER;
	}

	// std::set<std::string> charsets; // Used to check repertoires.
	protected Set<String> charsets = new HashSet<>();

	protected int checkCharset(String text) {
		// return charsets.count(text) > 0 ? MySQLLexer::UNDERSCORE_CHARSET :
		// MySQLLexer::IDENTIFIER;
		return charsets.contains(text) ? MySQLLexer.UNDERSCORE_CHARSET : MySQLLexer.IDENTIFIER;
	}

	protected boolean checkVersion(String text) {
		if (text.length() < 8) // Minimum is: /*!12345
			return false;

		// Skip version comment introducer.
		// long version = std::stoul(text.c_str() + 3, NULL, 10);
		long version = Long.valueOf(text.substring(3)); // Minimum is: /*!12345
		if (version <= serverVersion) {
			inVersionComment = true;
			return true;
		}
		return false;

	}

}
